<?php


namespace Mall\Api\Utils;


use Wonfu\Core\Utils;

class ArrayHelper
{
    public static function myArrayColumn(array $arr, $column, $indexKey = null):array
    {
        if (!is_array($arr) || empty($arr)) {
            return [];
        }

        $res = [];
        foreach ($arr as $obj) {
            $_key = null;
            $_data = $obj;

            if ($indexKey) {
                $indexKey = Utils::toBigHump($indexKey);
                $_key = call_user_func([$obj, "get{$indexKey}"]);
            }

            if ($column) {
                $column = Utils::toBigHump($column);
                $_data = call_user_func([$obj, "get{$column}"]);
            }

            if ($_key) {
                $res[$_key] = $_data;
            } else {
                $res[] = $_data;
            }
        }

        return $res;
    }
}